<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="结算的对账批次号" prop="checkBatchNo">
        <el-input
          v-model="queryParams.checkBatchNo"
          placeholder="请输入结算的对账批次号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button type="success" size="mini" @click="resetQuery">确认结算</el-button>
      </el-form-item>
    </el-form>

<!--    <el-row :gutter="10" class="mb8">-->
<!--      <el-col :span="1.5">-->
<!--        <el-button-->
<!--          type="primary"-->
<!--          plain-->
<!--          icon="el-icon-plus"-->
<!--          size="mini"-->
<!--          @click="handleAdd"-->
<!--          v-hasPermi="['clearings:clearing:add']"-->
<!--        >新增</el-button>-->
<!--      </el-col>-->
<!--      <el-col :span="1.5">-->
<!--        <el-button-->
<!--          type="success"-->
<!--          plain-->
<!--          icon="el-icon-edit"-->
<!--          size="mini"-->
<!--          :disabled="single"-->
<!--          @click="handleUpdate"-->
<!--          v-hasPermi="['clearings:clearing:edit']"-->
<!--        >修改</el-button>-->
<!--      </el-col>-->
<!--      <el-col :span="1.5">-->
<!--        <el-button-->
<!--          type="danger"-->
<!--          plain-->
<!--          icon="el-icon-delete"-->
<!--          size="mini"-->
<!--          :disabled="multiple"-->
<!--          @click="handleDelete"-->
<!--          v-hasPermi="['clearings:clearing:remove']"-->
<!--        >删除</el-button>-->
<!--      </el-col>-->
<!--      <el-col :span="1.5">-->
<!--        <el-button-->
<!--          type="warning"-->
<!--          plain-->
<!--          icon="el-icon-download"-->
<!--          size="mini"-->
<!--          @click="handleExport"-->
<!--          v-hasPermi="['clearings:clearing:export']"-->
<!--        >导出</el-button>-->
<!--      </el-col>-->
<!--      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>-->
<!--    </el-row>-->

    <el-table v-loading="loading" :data="clearingList" ref="multipleTable" @selection-change="handleSelectionChange">
      <el-table-column
        type="selection"
        width="55">
      </el-table-column>
<!--      <el-table-column type="selection" width="55" align="center" />-->
<!--      <el-table-column label="主键 自增" align="center" prop="id" />-->
<!--      <el-table-column label="商户ID" align="center" prop="businessId" />-->
      <el-table-column label="结算的对账批次号" align="center" prop="checkBatchNo" />
      <el-table-column label="商户名称" align="center" prop="businessName" />
<!--      <el-table-column label="对账年月日(yyyymmdd)" align="center" prop="checkDay" />-->
<!--      <el-table-column label="结算的对账批次ID" align="center" prop="checkBatchId" />-->
<!--      <el-table-column label="结算的对账批次明细ID" align="center" prop="checkBatchDetailId" />-->
<!--      <el-table-column label="交易流水号，支付订单的支付订单号" align="center" prop="payOrderNo" />-->
<!--      <el-table-column label="渠道名称(拉卡拉账单类型) 1:代付" align="center" prop="billType" />-->
<!--      <el-table-column label="对账确认时间" align="center" prop="checkConfirmDate" width="180">-->
<!--        <template slot-scope="scope">-->
<!--          <span>{{ parseTime(scope.row.checkConfirmDate, '{y}-{m}-{d}') }}</span>-->
<!--        </template>-->
<!--      </el-table-column>-->
      <el-table-column label="结算金额" align="center" prop="amount" />
      <el-table-column label="交易日期" align="center" prop="tradeDateZf" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.tradeDateZf, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="结算状态" align="center" prop="status">
        <template slot-scope="scope">
          <span v-if="scope.row.status==0">
            未确认
          </span>
          <span v-if="scope.row.status==1">
            已确认
          </span>
        </template>
      </el-table-column>
<!--      <el-table-column label="结算确认状态" align="center" prop="clearingConfirmState" />-->
<!--      <el-table-column label="结算确认人" align="center" prop="clearingConfirmUserId" />-->
<!--      <el-table-column label="结算确认时间" align="center" prop="clearingConfirmDate" width="180">-->
<!--        <template slot-scope="scope">-->
<!--          <span>{{ parseTime(scope.row.clearingConfirmDate, '{y}-{m}-{d}') }}</span>-->
<!--        </template>-->
<!--      </el-table-column>-->
<!--      <el-table-column label="备注" align="center" prop="remarks" />-->
<!--      <el-table-column label="预留字段1" align="center" prop="reserve1" />-->
<!--      <el-table-column label="预留字段2" align="center" prop="reserve2" />-->
<!--      <el-table-column label="预留字段3" align="center" prop="reserve3" />-->
<!--      <el-table-column label="预留字段4" align="center" prop="reserve4" />-->
<!--      <el-table-column label="预留字段5" align="center" prop="reserve5" />-->
<!--      <el-table-column label="删除标识,0:未删除，1：删除" align="center" prop="delFlg" />-->
<!--      <el-table-column label="创建用户ID" align="center" prop="createUserid" />-->
<!--      <el-table-column label="更新用户ID" align="center" prop="updateUserid" />-->
<!--      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">-->
<!--        <template slot-scope="scope">-->
<!--          <el-button-->
<!--            size="mini"-->
<!--            type="text"-->
<!--            icon="el-icon-edit"-->
<!--            @click="handleUpdate(scope.row)"-->
<!--            v-hasPermi="['clearings:clearing:edit']"-->
<!--          >修改</el-button>-->
<!--          <el-button-->
<!--            size="mini"-->
<!--            type="text"-->
<!--            icon="el-icon-delete"-->
<!--            @click="handleDelete(scope.row)"-->
<!--            v-hasPermi="['clearings:clearing:remove']"-->
<!--          >删除</el-button>-->
<!--        </template>-->
<!--      </el-table-column>-->
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

<!--    &lt;!&ndash; 添加或修改结算对话框 &ndash;&gt;-->
<!--    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>-->
<!--      <el-form ref="form" :model="form" :rules="rules" label-width="80px">-->
<!--        <el-form-item label="商户ID" prop="businessId">-->
<!--          <el-input v-model="form.businessId" placeholder="请输入商户ID" />-->
<!--        </el-form-item>-->
<!--        <el-form-item label="商户名称" prop="businessName">-->
<!--          <el-input v-model="form.businessName" placeholder="请输入商户名称" />-->
<!--        </el-form-item>-->
<!--        <el-form-item label="对账年月日(yyyymmdd)" prop="checkDay">-->
<!--          <el-input v-model="form.checkDay" placeholder="请输入对账年月日(yyyymmdd)" />-->
<!--        </el-form-item>-->
<!--        <el-form-item label="结算的对账批次ID" prop="checkBatchId">-->
<!--          <el-input v-model="form.checkBatchId" placeholder="请输入结算的对账批次ID" />-->
<!--        </el-form-item>-->
<!--        <el-form-item label="结算的对账批次号" prop="checkBatchNo">-->
<!--          <el-input v-model="form.checkBatchNo" placeholder="请输入结算的对账批次号" />-->
<!--        </el-form-item>-->
<!--        <el-form-item label="结算的对账批次明细ID" prop="checkBatchDetailId">-->
<!--          <el-input v-model="form.checkBatchDetailId" placeholder="请输入结算的对账批次明细ID" />-->
<!--        </el-form-item>-->
<!--        <el-form-item label="交易流水号，支付订单的支付订单号" prop="payOrderNo">-->
<!--          <el-input v-model="form.payOrderNo" placeholder="请输入交易流水号，支付订单的支付订单号" />-->
<!--        </el-form-item>-->
<!--        <el-form-item label="对账确认时间" prop="checkConfirmDate">-->
<!--          <el-date-picker clearable-->
<!--            v-model="form.checkConfirmDate"-->
<!--            type="date"-->
<!--            value-format="yyyy-MM-dd"-->
<!--            placeholder="请选择对账确认时间">-->
<!--          </el-date-picker>-->
<!--        </el-form-item>-->
<!--        <el-form-item label="结算金额" prop="amount">-->
<!--          <el-input v-model="form.amount" placeholder="请输入结算金额" />-->
<!--        </el-form-item>-->
<!--        <el-form-item label="交易日期" prop="tradeDateZf">-->
<!--          <el-date-picker clearable-->
<!--            v-model="form.tradeDateZf"-->
<!--            type="date"-->
<!--            value-format="yyyy-MM-dd"-->
<!--            placeholder="请选择交易日期">-->
<!--          </el-date-picker>-->
<!--        </el-form-item>-->
<!--        <el-form-item label="结算确认状态" prop="clearingConfirmState">-->
<!--          <el-input v-model="form.clearingConfirmState" placeholder="请输入结算确认状态" />-->
<!--        </el-form-item>-->
<!--        <el-form-item label="结算确认人" prop="clearingConfirmUserId">-->
<!--          <el-input v-model="form.clearingConfirmUserId" placeholder="请输入结算确认人" />-->
<!--        </el-form-item>-->
<!--        <el-form-item label="结算确认时间" prop="clearingConfirmDate">-->
<!--          <el-date-picker clearable-->
<!--            v-model="form.clearingConfirmDate"-->
<!--            type="date"-->
<!--            value-format="yyyy-MM-dd"-->
<!--            placeholder="请选择结算确认时间">-->
<!--          </el-date-picker>-->
<!--        </el-form-item>-->
<!--        <el-form-item label="备注" prop="remarks">-->
<!--          <el-input v-model="form.remarks" type="textarea" placeholder="请输入内容" />-->
<!--        </el-form-item>-->
<!--        <el-form-item label="预留字段1" prop="reserve1">-->
<!--          <el-input v-model="form.reserve1" placeholder="请输入预留字段1" />-->
<!--        </el-form-item>-->
<!--        <el-form-item label="预留字段2" prop="reserve2">-->
<!--          <el-input v-model="form.reserve2" placeholder="请输入预留字段2" />-->
<!--        </el-form-item>-->
<!--        <el-form-item label="预留字段3" prop="reserve3">-->
<!--          <el-input v-model="form.reserve3" placeholder="请输入预留字段3" />-->
<!--        </el-form-item>-->
<!--        <el-form-item label="预留字段4" prop="reserve4">-->
<!--          <el-input v-model="form.reserve4" placeholder="请输入预留字段4" />-->
<!--        </el-form-item>-->
<!--        <el-form-item label="预留字段5" prop="reserve5">-->
<!--          <el-input v-model="form.reserve5" placeholder="请输入预留字段5" />-->
<!--        </el-form-item>-->
<!--        <el-form-item label="删除标识,0:未删除，1：删除" prop="delFlg">-->
<!--          <el-input v-model="form.delFlg" placeholder="请输入删除标识,0:未删除，1：删除" />-->
<!--        </el-form-item>-->
<!--        <el-form-item label="创建用户ID" prop="createUserid">-->
<!--          <el-input v-model="form.createUserid" placeholder="请输入创建用户ID" />-->
<!--        </el-form-item>-->
<!--        <el-form-item label="更新用户ID" prop="updateUserid">-->
<!--          <el-input v-model="form.updateUserid" placeholder="请输入更新用户ID" />-->
<!--        </el-form-item>-->
<!--      </el-form>-->
<!--      <div slot="footer" class="dialog-footer">-->
<!--        <el-button type="primary" @click="submitForm">确 定</el-button>-->
<!--        <el-button @click="cancel">取 消</el-button>-->
<!--      </div>-->
<!--    </el-dialog>-->
  </div>
</template>

<script>
import { listClearing, getClearing, delClearing, addClearing, updateClearing } from "@/api/clearings/clearing";

export default {
  name: "Clearing",
  data() {
    return {
      //多选框
      multipleSelection: [],
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 结算表格数据
      clearingList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        status:null,
        pageNum: 1,
        pageSize: 10,
        businessId: null,
        businessName: null,
        checkDay: null,
        checkBatchId: null,
        checkBatchNo: null,
        checkBatchDetailId: null,
        payOrderNo: null,
        billType: null,
        checkConfirmDate: null,
        amount: null,
        tradeDateZf: null,
        clearingConfirmState: null,
        clearingConfirmUserId: null,
        clearingConfirmDate: null,
        remarks: null,
        reserve1: null,
        reserve2: null,
        reserve3: null,
        reserve4: null,
        reserve5: null,
        delFlg: null,
        createUserid: null,
        updateUserid: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        checkDay: [
          { required: true, message: "对账年月日(yyyymmdd)不能为空", trigger: "blur" }
        ],
        checkBatchId: [
          { required: true, message: "结算的对账批次ID不能为空", trigger: "blur" }
        ],
        checkBatchNo: [
          { required: true, message: "结算的对账批次号不能为空", trigger: "blur" }
        ],
        checkBatchDetailId: [
          { required: true, message: "结算的对账批次明细ID不能为空", trigger: "blur" }
        ],
        checkConfirmDate: [
          { required: true, message: "对账确认时间不能为空", trigger: "blur" }
        ],
        amount: [
          { required: true, message: "结算金额不能为空", trigger: "blur" }
        ],
        tradeDateZf: [
          { required: true, message: "交易日期不能为空", trigger: "blur" }
        ],
        createUserid: [
          { required: true, message: "创建用户ID不能为空", trigger: "blur" }
        ],
        createTime: [
          { required: true, message: "创建时间不能为空", trigger: "blur" }
        ],
        updateUserid: [
          { required: true, message: "更新用户ID不能为空", trigger: "blur" }
        ],
        updateTime: [
          { required: true, message: "更新时间不能为空", trigger: "blur" }
        ]
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询结算列表 */
    getList() {
      this.loading = true;
      listClearing(this.queryParams).then(response => {
        this.clearingList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        businessId: null,
        businessName: null,
        checkDay: null,
        checkBatchId: null,
        checkBatchNo: null,
        checkBatchDetailId: null,
        payOrderNo: null,
        billType: null,
        checkConfirmDate: null,
        amount: null,
        tradeDateZf: null,
        clearingConfirmState: null,
        clearingConfirmUserId: null,
        clearingConfirmDate: null,
        remarks: null,
        reserve1: null,
        reserve2: null,
        reserve3: null,
        reserve4: null,
        reserve5: null,
        delFlg: null,
        createUserid: null,
        createTime: null,
        updateUserid: null,
        updateTime: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 确认结算按钮操作 */
    updateStatus() {
       let checkBatchNos = [];
         this.multipleSelection.map(item=>{
        checkBatchNos.push(item.checkBatchNo)
      })
      this.$confirm("你要确认结算对账批次号为"+checkBatchNos+"的数据吗").then(()=>{
        alert("确认结算成功")
      })

    },

    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
      this.multipleSelection = val;
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加结算";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getClearing(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改结算";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateClearing(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addClearing(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除结算编号为"' + ids + '"的数据项？').then(function() {
        return delClearing(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('clearings/clearing/export', {
        ...this.queryParams
      }, `clearing_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
